package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.service.CheckInRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/check-in-records")
@RequiredArgsConstructor
@Tag(name = "打卡记录管理", description = "打卡记录查询接口")
public class CheckInRecordController {
    private final CheckInRecordService recordService;

    /**
     * 获取指定活动的已打卡日期
     */
    @GetMapping("/checked-dates")
    @Operation(summary = "获取已打卡日期", description = "根据活动ID获取已打卡的日期列表")
    public ApiResponse<List<String>> getCheckedDates(
            @Parameter(description = "活动ID")
            @RequestParam Long activityId) {
        log.info("开始获取已打卡日期: activityId={}", activityId);

        try {
            List<String> dates = recordService.getCheckedDates(activityId);
            log.info("成功获取活动{}的{}个打卡日期", activityId, dates.size());
            return ApiResponse.success("已打卡日期获取成功", dates);
        } catch (Exception e) {
            log.error("获取打卡日期失败: activityId={}", activityId, e);
            return ApiResponse.fail("获取打卡日期失败: " + e.getMessage());
        }
    }
}
